import 'dart:math';

import 'package:flutter/material.dart';

class RotateAnimationWidget extends StatefulWidget {
  RotateAnimationWidget({
    this.speed = 500,
    this.isPlaying = true,
    this.child,
  });

  final int speed;
  final bool isPlaying;
  final Widget? child;

  @override
  State<StatefulWidget> createState() {
    return _RotateAnimationWidgetState();
  }
}

class _RotateAnimationWidgetState extends State<RotateAnimationWidget> with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(duration: Duration(milliseconds: widget.speed), vsync: this);
    _controller.repeat();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _controller,
      builder: (BuildContext context, Widget? child) {
        return Transform.rotate(
          angle: _controller.value * (pi / 2),
          child: widget.child,
        );
      },
    );
  }
}
